export class Queue<T> {
  constructor () {
    this.obj = {}
    this.count = 0
    this.lowestCount = 0
  }
  obj: {
    [key: number]: T
  }
  count: number
  // 记录最小位置
  lowestCount: number

  value () {
    return this.obj
  }

  // 判断是否为空
  isEmpty () {
    return !this.size()
  }

  // 长度
  size () {
    return this.count - this.lowestCount
  }

  // 插入数据-尾部插入
  enqueue (args: T) {
    this.obj[this.count] = args
    this.count++
  }

  // 取出数据 第一个数据
  dequeue () {
    if (this.isEmpty()) {
      return undefined
    }
    let res = this.obj[this.lowestCount] as T
    delete this.obj[this.lowestCount]
    this.lowestCount++
    return res
  }

  // 清除
  clear (){
    this.obj = {}
    this.count = 0
    this.lowestCount = 0
  }
}

